import logging
import sys
from colorama import Fore, Back, Style

print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')
 
# 获取对象
def get_logger():
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
 
    if not logger.handlers:
        ch = logging.StreamHandler(sys.stdout)
        ch.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            " %(message)s")
        ch.setFormatter(formatter)
        logger.addHandler(ch)
    return logger
 
#通过静态成员方法来调用
class Log:
 
    logger = get_logger()
 
    @staticmethod
    def debug(msg):
        Log.logger.debug(Fore.WHITE + "[DEBUG]: " + str(msg) + Style.RESET_ALL)
 
    @staticmethod
    def info(msg):
        Log.logger.info(Fore.GREEN + "[INFO]: " + str(msg) + Style.RESET_ALL)
 
    @staticmethod
    def warning(msg):
        Log.logger.warning("\033[38;5;214m" + "[WARNING]: " + str(msg) + "\033[m")
 
    @staticmethod
    def error(msg):
        Log.logger.error(Fore.RED + "[ERROR]: " + str(msg) + Style.RESET_ALL)
 
    @staticmethod
    def critical(msg):
        Log.logger.critical(Fore.RED + "[CRITICAL]: " + str(msg) + Style.RESET_ALL)

if __name__ == '__main__':
    log = Log()
    log.debug('debug')
    log.info('info')
    log.warning('警告')
    log.error('报错')
    log.critical('严重')
